package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.ZTreeNode;
import com.isunland.managesystem.utils.LogUtil;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 联网从数据字典中获取列表,特别的是获取的是name,传递给后台的是customAttr.
 *
 * @author wangyanan
 */
public class DataDictDialogFragment extends BaseNetworkDialogFragment {

  private static final String EXTRA_DICT_FLG = "com.isunland.managesystem.ui.EXTRA_DICT_FLG";
  private String mDictFlg;

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      ZTreeNode[] customerContacts = new Gson().fromJson(arg0, ZTreeNode[].class);

      for (int i = 0; i < customerContacts.length; i++) {
        list.add(new CustomerDialog(customerContacts[i].getName(),
            customerContacts[i].getCustomAttrs()));
      }

      //			list.add(new CustomerDialog("草稿", DataStatus.NEW));
      //			list.add(new CustomerDialog("审核中", DataStatus.WAIT_CHECK));
      //			list.add(new CustomerDialog("已审核", DataStatus.CHECK_PASS));
      //			list.add(new CustomerDialog("终止", DataStatus.ABORT));
      //			list.add(new CustomerDialog("全部", DataStatus.ALL));
      //			for (int i = 0; i < customerContacts.getDataList().size(); i++) {
      //				list.add(new CustomerDialog(customerContacts.getDataList().get(i).getStaffName(),
      //						customerContacts.getDataList().get(i).getId()+""));
      //			}
    } catch (Exception e) {
      LogUtil.e(TAG, "Exception", e);
      return null;
    }

    return list;
  }

  //	@Override
  //	protected void emptyToast() {
  //
  //		Toast.makeText(getActivity(), R.string.notRelativePer, Toast.LENGTH_SHORT).show();
  //	}

  @Override public String getUrl() {

    return ApiConst.URL_CUSTOMER_UNIT_STATE;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("dictFlg", mDictFlg);
    return params;
  }

  /**
   * @param dictFlg 数据字典标识.
   */
  public static DataDictDialogFragment newInstance(String dictFlg) {
    Bundle argsBundle = new Bundle();
    argsBundle.putString(EXTRA_DICT_FLG, dictFlg);
    DataDictDialogFragment fragment = new DataDictDialogFragment();
    fragment.setArguments(argsBundle);
    return fragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    mDictFlg = getArguments().getString(EXTRA_DICT_FLG);
    if (mDictFlg == null) {
      mDictFlg = "";
    }
    super.onCreate(savedInstanceState);
  }
}
